//
//  UIBarButtonItem+Addition.m
//  DatangLife
//
//  Created by 娜 on 2018/4/23.
//  Copyright © 2018年 DatangLife. All rights reserved.
//

#import "UIBarButtonItem+Addition.h"

@implementation UIBarButtonItem (Addition)
+ (UIBarButtonItem *)barButtonItemWithImage:(UIImage *)image highImage:(UIImage *)highImage target:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
{
    // 创建button样式
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

    // 设置button背景图片
    [btn setImage:image forState:UIControlStateNormal];
     btn.imageEdgeInsets = UIEdgeInsetsMake(0, -14, 0, 0);
    // 设置button高亮状态的背景图片
    [btn setBackgroundImage:highImage forState:UIControlStateHighlighted];
    [btn sizeToFit];
    // 设置button的监听方法
    [btn addTarget:target action:action forControlEvents:controlEvents];
    
    return  [[UIBarButtonItem alloc] initWithCustomView:btn];
}
@end
